<template>
  <van-form @submit="onSubmit">
    <van-field colon v-model="PID.P" type="number" label="PID-P"/>
    <van-field colon v-model="PID.I" type="number" label="PID-I"/>
    <van-field colon v-model="PID.D" type="number" label="PID-D"/>

    <div style="margin: 16px;">
      <van-button round block type="info" native-type="submit">提交</van-button>
    </div>
  </van-form>
</template>

<script>
import Vue from 'vue';
import {Form, Field, Toast} from 'vant';
import {getAction, postAction} from "@/util/request";

Vue.use(Form).use(Field).use(Toast);
export default {
  name: "PID",
  data() {
    return {
      PID: {
        P: 0,
        I: 0,
        D: 0
      },
      url: {
        PID: "/PID"
      }
    }
  },
  mounted() {
    getAction(this.url.PID)
        .then(res => {
          this.PID = res
        })
  },
  methods: {
    onSubmit(values) {
      getAction(this.url.PID, {
        P: new Number(this.PID.P || 0),
        I: new Number(this.PID.I || 0),
        D: new Number(this.PID.D || 0)
      })
          .then(res => {
            Toast.success({message: `保存成功！\r\nP:${res.P}\r\nI:${res.I}\r\nD:${res.D}`, position: 'top'})
          })
    }
  },

}
</script>

<style scoped>

</style>
